﻿@{
    ViewBag.Title = "调查问卷";
}
@section header{

}
<partial name="_page_list" />
@section scripts{
    <script>
        var baseUrl = "/Survey/SurQuestionNaire";
        $(function () {
            gridList();
        })
        function gridList() {
            var $gridList = $("#gridList");
            $gridList.dataGrid({
                url: baseUrl + "GetJGridPageDataJson",
                datatype: "json",
                height: $(window).height() - 128,
                mtype: "POST",
                colModel: [
                    { label: "主键", name: "ID", hidden: true, key: true },

                    { label: '问卷名称', name: 'SurName', align: 'left' },
                    { label: '描述', name: 'SurContent', align: 'left' },
                    { label: '共享', name: 'IsShare', align: 'left' },
                    { label: '发布方式', name: 'FilterModel', align: 'left' },
                    { label: '创建时间', name: 'CreateTime', align: 'left' },
                    { label: '完成情况', name: 'Completed', align: 'left' },
                    { label: '状态', name: 'SurStatus', align: 'left' },
                    { label: '收集量', name: 'CollectionAmount', align: 'left' },
                    { label: '已收集数量', name: 'Amounted', align: 'left' },
                    { label: '目标用户', name: 'TargetUser', align: 'left' },
                    { label: '质量控制', name: 'QualityControl', align: 'left' },
                    { label: '调研结果', name: 'SurResult', align: 'left' },
                    { label: '内容', name: 'JSONContent', align: 'left' },
                    { label: '预览JSON', name: 'JSONPreview', align: 'left' },
                    { label: '发布JSON', name: 'JSONPublish', align: 'left' },
                    { label: '发布时间', name: 'PublishTime', align: 'left' },
                    { label: '收集开始时间', name: 'SurStartDate', align: 'left' },
                    { label: '收集结束时间', name: 'SurEndDate', align: 'left' },
                    { label: '未锁定', name: 'IsUnlocked', align: 'left' },
                    { label: '在线', name: 'IsOnline', align: 'left' },
                    { label: '投票类型', name: 'VoteType', align: 'left' },
                    { label: '有效开始时间', name: 'EnableDate', align: 'left' },
                    { label: '有效截止时间', name: 'DisableDate', align: 'left' },
                    {
                        label: '排序', name: 'OrderBy', width: 100, align: 'center',
                        formatter: function (cellvalue, options, rowObject) {
                            var keyId = rowObject.ID;
                            return "<input type='text' name='OrderBy[" + keyId + "]' autocomplete='off' style='width: 50px; height: 20px;' onchange='update_field(\"" + keyId + "\",this.value)' value=" + cellvalue + " />";
                        }
                    },

                    {
                        label: '添加时间', name: 'AddTime', width: 120, align: 'center',
                        formatter: "date", formatoptions: { srcformat: 'Y-m-d H:i:s', newformat: 'Y-m-d H:i:s' }
                    }
                ],
                rowNum: 20,
                rowList: [20, 50, 100],
                pager: '#gridPager',
                sortname: 'OrderBy',
                sortorder: "asc",
                viewrecords: true,
                autowidth: true
            });
            $("#btn_search").click(function () {
                $gridList.jqGrid('setGridParam', {
                    postData: { keyword: $("#txt_keyword").val() },
                }).trigger('reloadGrid');
            });
        }
        function btn_add() {
            $.modalOpen({
                id: "Form",
                title: "新增",
                url: baseUrl + "Form",
                width: "700px",
                height: "440px",
                callBack: function (iframeId) {
                    top.frames[iframeId].submitForm();
                }
            });
        }
        function btn_edit() {
            var keyValue = $("#gridList").jqGridRowValue().ID;
            $.modalOpen({
                id: "Form",
                title: "修改",
                url: baseUrl + "Form?keyValue=" + keyValue,
                width: "700px",
                height: "440px",
                callBack: function (iframeId) {
                    top.frames[iframeId].submitForm();
                }
            });
        }
        function btn_delete() {
            $.deleteForm({
                url: baseUrl + "DeleteForm",
                param: { keyValue: $("#gridList").jqGridRowValue().ID },
                success: function () {
                    $.currentWindow().$("#gridList").resetSelection();
                    $.currentWindow().$("#gridList").trigger("reloadGrid");
                }
            })
        }
        function btn_details() {
            var keyValue = $("#gridList").jqGridRowValue().ID;
            $.modalOpen({
                id: "Details",
                title: "查看",
                url: baseUrl + "Details?keyValue=" + keyValue,
                width: "700px",
                height: "490px",
                btn: null,
            });
        }
        function Switch(keyId) {
            $.ajax({
                url: baseUrl + "Switch?keyId=" + keyId,
                data: {},
                type: "POST",
                dataType: "json",
                async: false,
                success: function () {
                    $.currentWindow().$("#gridList").resetSelection();
                    $.currentWindow().$("#gridList").trigger("reloadGrid");
                }
            });
        }
        function update_field(keyId, cellvalue) {
            $.ajax({
                url: baseUrl + "UpdateOrderBy?keyId=" + keyId + "&value=" + cellvalue,
                data: {},
                dataType: "json",
                type: "POST",
                success: function () {
                    $.currentWindow().$("#gridList").resetSelection();
                    $.currentWindow().$("#gridList").trigger("reloadGrid");
                }
            });
        }
    </script>
}